import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../views/layout.vue'
import storage from 'store'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/userType',
    component: () => import('../views/login/userType.vue'),
    meta: { isKeepAlive: true }
  },
  {
    path: '/userType',
    name: 'userType',
    component: () => import('../views/login/userType.vue')
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/login/login.vue')
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('../views/login/register.vue')
  },
  // 开启评估
  {
    path: '/home/open_pg',
    name: 'openPg',
    component: () => import('../views/home/openPg.vue')
  },
  // 评估处理
  {
    path: '/home_/handle_pg',
    name: 'handlePg',
    component: () => import('../views/home_/handlePg.vue'),
    meta: { isKeepAlive: true }
  },
  // 评分详情
  {
    path: '/user/scoring',
    name: 'scoringDetail',
    component: () => import('../views/user/scoringDetail.vue')
  },
  // 手机号
  {
    path: '/phone',
    name: 'phone',
    component: () => import('../views/me/phone.vue')
  },
  // 密码
  {
    path: '/password',
    name: 'password',
    component: () => import('../views/me/password.vue')
  },
  // 搜索医护
  {
    path: '/yihu/search',
    name: 'searchYihu',
    component: () => import('../views/yihu/searchYihu.vue')
  },
  // 搜索口服药物
  {
    path: '/yihu/searchKoufu',
    name: 'searchKoufu',
    component: () => import('../views/yihu/searchKoufu.vue')
  },
  // 搜索静脉注射
  {
    path: '/yihu/serachJingmai',
    name: 'serachJingmai',
    component: () => import('../views/yihu/serachJingmai.vue')
  },
  // CINV综合管理信息
  {
    path: '/user/infoAdmin',
    name: 'infoAdmin',
    component: () => import('../views/user/infoAdmin.vue')
  },
  // 搜过关联视频
  {
    path: '/me/searchVideo',
    name: 'searchVideo',
    component: () => import('../views/me/searchVideo.vue')
  },
  // 患者详情
  {
    path: '/user/moreInfo',
    name: 'moreInfo',
    component: () => import('../views/user/moreInfo.vue')
  },
  // 患者更多信息
  {
    path: '/user/userDetail',
    name: 'userDetail',
    component: () => import('../views/user/userDetail.vue')
  },
  // 医护提交综合信息
  {
    path: '/yihu/yihumation',
    name: 'yihumation',
    component: () => import('../views/yihu/yihumation.vue')
  },
  // 患者控制不良综合信息
  {
    path: '/user/Information',
    name: 'userDetail',
    component: () => import('../views/user/Information.vue')
  },
  // 医护-套餐管理
  {
    path: '/yihu/packageManage',
    name: 'packageManage',
    component: () => import('../views/yihu/packageManage.vue')
  },
  // 新增套餐
  {
    path: '/yihu/addPackage',
    name: 'addPackage',
    component: () => import('../views/yihu/addPackage.vue')
  },
  // 修改身高
  {
    path: '/me/height',
    name: 'height',
    component: () => import('../views/me_/height.vue')
  },
  // 修改体重
  {
    path: '/me/weight',
    name: 'weight',
    component: () => import('../views/me_/weight.vue')
  },
  // 修改性别
  {
    path: '/me/gender',
    name: 'gender',
    component: () => import('../views/me_/gender.vue')
  },
  {
    path: '/me/birthday',
    name: 'birthday',
    component: () => import('../views/me_/birthday.vue')
  },
  // 修改职称
  {
    path: '/me/professional',
    name: 'professional',
    component: () => import('../views/me/professional.vue')
  },
  // 修改类型
  {
    path: '/me/type',
    name: 'type',
    component: () => import('../views/me/type.vue')
  },
  // 修改 科室 医院名称 城市 省市
  {
    path: '/me/address',
    name: 'address',
    component: () => import('../views/me/address.vue')
  },
  {
    path: '/home',
    component: Layout,
    children: [
      // meta就是定义路由时一个特殊的设置项，名就是meta,它的值是一个自定义的对象，其中可以放一些数据信息
      { path: '/home', name: 'Home', component: () => import('../views/home/index.vue'), meta: { isKeepAlive: false } },
      { path: '/home_', name: 'Home_', component: () => import('../views/home_/index.vue'), meta: { isKeepAlive: false } },
      { path: '/yihu', name: 'Yihu', component: () => import('../views/yihu/index.vue') },
      { path: '/user', name: 'User', component: () => import('../views/user/index.vue') },
      { path: '/me', name: 'Me', component: () => import('../views/me/index.vue') },
      { path: '/me_', name: 'Me_', component: () => import('../views/me_/index.vue') }
    ]
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  // 是否有token
  const isAuthenticated = storage.get('token')
  const WhiteList = ['Login', 'register', 'userType'] // 路由白名单
  if (!WhiteList.includes(to.name) && !isAuthenticated) next({ name: 'Login' })
  else next()
})
export default router
